'''
Author: didiplus
Date: 2024-09-10 11:30:33
LastEditTime: 2024-09-10 11:31:55
LastEditors: didiplus
Description: 兔子产子问题
FilePath: \pythonscript\python\趣学Python算法100例\2、兔子产子\demo.py
'''


def rabbit_pairs(months):
    if months <= 0:
        return 0
    elif months == 1 or months == 2:
        return 1

    # 初始化前两个数值
    prev1, prev2 = 1, 1

    # 从第三个月开始计算
    for month in range(3, months + 1):
        current = prev1 + prev2
        prev1, prev2 = prev2, current

    return current


if __name__ == "__main__":
# 计算30个月的兔子总对数
    months = 30
    total_rabbits = rabbit_pairs(months)
    print(f"在第 {months} 个月，兔子的总对数为: {total_rabbits}")